<template>
<div>
    <AutoQuery ref="auto-query" :query="query" :page="page"></AutoQuery>
    <AutoTable :columns="columns1" :data="demand_list" :page="page"></AutoTable>
</div>
</template>
<script>
import Page from "@/common/model/Page";
import AutoTable from "@/common/components/AutoTable";
import AutoQuery from "@/common/components/AutoQuery";
import parent from "../Parent";
export default {
    extends:parent,
    components: {
        AutoTable,AutoQuery
    },
    home:'name',
    data () {
        var form = {
            demand_type:"0",
            search:"",     
            begin_time: '',
            end_time: ''
        };
        return {
            page: new Page("search/demand_item", this.formatItem(form)),
            form: form,
            query: { // 查询条件
                search_number: { type: "input", label: "编号：",placeholder: "请输入所查信息的编号" },
                search: { type: "input", label: "关键字：",placeholder: "请输入所查信息的标题或者关键字..." },
                m_type: { type: "select", label: "需求类别：", default: "0", placeholder: "请选择需求类别", options: [] },
                begin_time: { type: "date", label: "日期", placeholder: "选择开始时间" },
                end_time: { type: "date", placeholder: "选择截止时间", handleValue: value => { return value + 24*60*60*1000 } },
            },
            columns1: [
                {
                    title: '编号', render:(h, params) => {
                        return h('div', params.row.number);
                    }
                },
                {
                  title: '标题',
                  render: (h ,params) => {
                    return h('div',[
                      h('strong', params.row.title)
                    ])
                  }
                },
                {
                  title: '需求类别',
                  render: (h, params) => {
                    return h('div',[
                      h('strong', params.row.m_type)
                    ])
                  }
                },
                {
                  title: '所属行业',
                  render: (h, params) => {
                    return h('div', [
                      h('strong', params.row.demand_industry)
                    ])
                  }
                },
                // {
                //   title: '公司名称',
                //   render: (h, params) => {
                //     return h('div', [
                //       h('strong', params.row.member.enterprise_name)
                //     ])
                //   }
                // },
                {
                  title: '联系人',
                  render: (h, params) => {
                    return h('div', [
                      h('strong', params.row.demand_master)
                    ])
                  }
                },
                // {
                //   title:'联系电话',
                //   render: (h, params) => {
                //     return h('div', [
                //       h('strong', params.row.demand_tele)
                //     ])
                //   }
                // },
                {
                    title: '发布时间',
                    sortable: "custom",
                    key: 'create_time',
                    render: (h, params) => {
                       return h('div', new Date(parseInt(params.row.create_time)).toLocaleDateString()+" "+new Date(parseInt(params.row.create_time)).getHours()+":"+new Date(parseInt(params.row.create_time)).getMinutes());
                    }
                }
            ],
        }
    },
    computed: {
        demand_list(){
            return this.page.list;
        }
    },
    methods: {
        formatItem(data) {    
            return {
                demand_type:data.demand_type,
                search_number:data.search_number,
                search:data.search,
                begin_time: data.begin_time==""? "":Date.parse(new Date(data.begin_time)),
                end_time: data.end_time==""? "":Date.parse(new Date(data.end_time))+24*60*60*1000
            }
        },
        delete (index){
             this.$Modal.confirm({
                    title: '确认删除？',
                    content: '<p>继续删除，请点击确定按钮</p><br><p>取消，请点击取消按钮</p>',
                    onOk: () => {
                            this.api.post("feedback/delate_log",{ id: this.demand_list[index].id}, res =>{
                            this.$CustomMessage.success('删除成功!');
                            this.page.getData();
                        })
                    },
                    onCancel: () => {
                        this.$CustomMessage.info('取消删除');
                    }
            });   
        }
    },
    created() {
        this.process("dic_tree", () => { // 在字典树成功获取到后更新类别选择框
            var temp = this.$store.state.app.dicTree.usual_service.children.filter( elem => elem.url == "#" ).map( elem => {
                return { value: elem.name, label: elem.name };
            });
            this.query.m_type.options = [{ value: "*", label: "全部" }].concat(temp);
        });
    }
}
</script>
<style>
</style>